<template>
  <div class="app-container">
    <el-card style="border-radius: 10px">
      <el-form
        :model="queryParams"
        ref="queryForm"
        size="small"
        :inline="true"
        v-show="showSearch"
        label-width="100px"
      >
        <el-form-item label="报工类型" prop="feedbackType">
          <el-select
            v-model="queryParams.feedbackType"
            placeholder="请选择报工类型"
            clearable
          >
            <el-option
              v-for="dict in dict.type.mes_feedback_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="工作站名称" prop="workstationName">
          <el-input
            v-model="queryParams.workstationName"
            placeholder="请输入工作站名称"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="生产工单编号" prop="workorderCode">
          <el-input
            v-model="queryParams.workorderCode"
            placeholder="请输入生产工单编号"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="产品物料编码" prop="itemCode">
          <el-input
            v-model="queryParams.itemCode"
            placeholder="请输入产品物料编码"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="产品物料名称" prop="itemName">
          <el-input
            v-model="queryParams.itemName"
            placeholder="请输入产品物料名称"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="报工人" prop="nickName">
          <el-input
            v-model="queryParams.nickName"
            placeholder="请输入报工人名称"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="审核人" prop="recordNick">
          <el-input
            v-model="queryParams.recordNick"
            placeholder="请输入审核人"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="状态" prop="status">
          <el-select
            v-model="queryParams.status"
            placeholder="请选择状态"
            clearable
          >
            <el-option
              v-for="dict in dict.type.mes_order_status"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-search"
            size="mini"
            @click="handleQuery"
          >搜索
          </el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置
          </el-button>
        </el-form-item>
      </el-form>
    </el-card>
    <div style="height: 15px"></div>
    <el-card style="border-radius: 10px">
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="primary"
            icon="el-icon-plus"
            size="mini"
            @click="handleAdd"
            v-hasPermi="['mes:pro:feedback:add']"
          >新增
          </el-button>
        </el-col>
        <right-toolbar
          :showSearch.sync="showSearch"
          @queryTable="getList"
        ></right-toolbar>
      </el-row>
      <el-table
        border
        v-loading="loading"
        :data="feedbackList"
        @selection-change="handleSelectionChange"
      >
        <el-table-column label="报工类型" width="120px" align="center" prop="feedbackType">
          <template slot-scope="scope">
            <dict-tag
              :options="dict.type.mes_feedback_type"
              :value="scope.row.feedbackType"
            />
          </template>
        </el-table-column>
        <el-table-column
          label="工作站"
          width="120px"
          align="center"
          prop="workstationName"
          :show-overflow-tooltip="true"/>
        <el-table-column
          label="生产工单编号"
          width="150px"
          align="center"
          prop="workorderCode"
          :show-overflow-tooltip="true"/>
        <el-table-column
          label="产品物料编码"
          width="150px"
          align="center"
          prop="itemCode"
          :show-overflow-tooltip="true"/>
        <el-table-column
          label="产品物料名称"
          width="150px"
          align="center"
          prop="itemName"
          :show-overflow-tooltip="true"/>
        <el-table-column label="规格型号" align="center" prop="specification"/>
        <el-table-column
          label="报工数量"
          align="center"
          prop="quantityFeedback">
          <template slot-scope="scope">
            <el-tag type="primary">{{ scope.row.quantityFeedback }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column
          label="合格品数量"
          width="100px"
          align="center"
          prop="quantityQualified">
          <template slot-scope="scope">
            <el-tag type="success">{{ scope.row.quantityQualified }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column
          label="不良品数量"
          width="100px"
          align="center"
          prop="quantityUnquanlified">
          <template slot-scope="scope">
            <el-tag type="danger">{{ scope.row.quantityUnquanlified }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="报工人" align="center" prop="nickName">
          <template slot-scope="scope">
            <el-tag>{{ scope.row.nickName }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column
          label="报工时间"
          align="center"
          prop="feedbackTime"
          width="180"
        >
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.feedbackTime, "{y}-{m}-{d}") }}</span>
          </template>
        </el-table-column>
        <el-table-column label="审核人" align="center" prop="recordNick"/>
        <el-table-column label="状态" align="center" prop="status" fixed="right">
          <template slot-scope="scope">
            <dict-tag
              :options="dict.type.mes_order_status"
              :value="scope.row.status"
            />
          </template>
        </el-table-column>
        <el-table-column
          fixed="right"
          label="操作"
          align="center"
          width="180px"
        >
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-view"
              @click="handleInfoView(scope.row)"
              v-hasPermi="['mes:pro:feedback:query']"
            >查看
            </el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleUpdate(scope.row)"
              v-hasPermi="['mes:pro:feedback:tijiao']"
              v-if="scope.row.status === 'PREPARE'"
            >编辑
            </el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-circle-check"
              @click="handleUpdate(scope.row)"
              v-hasPermi="['mes:pro:feedback:shenhe']"
              v-if="scope.row.status === 'APPROVING' && scope.row.attr1 == 'Y'"
            >审核
            </el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              @click="handleDelete(scope.row)"
              v-hasPermi="['mes:pro:feedback:remove']"
              v-if="scope.row.status == 'PREPARE'"
            >删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </el-card>
    <!-- 添加或修改生产报工记录对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="960px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-row>
          <el-col :span="8">
            <el-form-item label="报工类型" prop="feedbackType">
              <el-select
                v-model="form.feedbackType"
                placeholder="请选择报工类型"
                :disabled="form.status==='PREPARE'?false:true">
                <el-option
                  v-for="dict in dict.type.mes_feedback_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="生产工单" prop="workorderCode">
              <el-input
                v-model="form.workorderCode"
                placeholder="请选择生产工单"
                :disabled="form.status==='PREPARE'?false:true"
              >
                <el-button
                  slot="append"
                  icon="el-icon-search"
                  @click="handleWorkorderSelect"
                  :disabled="form.status==='PREPARE'?false:true"
                ></el-button>
              </el-input>
            </el-form-item>
            <WorkorderSelect
              ref="woSelect"
              @onSelected="onWorkorderSelected"
            ></WorkorderSelect>
          </el-col>
          <el-col :span="8">
            <el-form-item label="生产任务" prop="taskCode">
              <el-input v-model="form.taskCode" placeholder="请选择生产任务" :disabled="form.status==='PREPARE'?false:true">
                <el-button
                  slot="append"
                  icon="el-icon-search"
                  @click="handleTaskSelect"
                  :disabled="form.status==='PREPARE'?false:true"
                ></el-button>
              </el-input>
            </el-form-item>
            <ProtaskSelect
              ref="taskSelect"
              :workorderId="form.workorderId"
              :taskStatus="taskStatus"
              @onSelected="onTaskSelected"
            >
            </ProtaskSelect>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="产品编码" prop="itemCode">
              <el-input v-model="form.itemCode" disabled/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="产品名称" prop="itemName">
              <el-input v-model="form.itemName" disabled/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="单位" prop="unitOfMeasure">
              <el-input v-model="form.unitOfMeasure" disabled/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="计价方式" prop="pricingMethod">
              <el-select v-model="form.pricingMethod" disabled placeholder="请选择来计价方式">
                <el-option
                  v-for="dict in dict.type.pro_pricing_method"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                  :disabled="true"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8" v-if="form.pricingMethod=='PIECEWORK'">
            <el-form-item label="标准计件单价" prop="price">
              <el-input v-model="form.price" disabled placeholder="请输入单价"/>
            </el-form-item>
          </el-col>
          <el-col :span="8" v-else-if="form.pricingMethod=='TIME'">
            <el-form-item label="标准计时单价" prop="price">
              <el-input v-model="form.price" disabled placeholder="请输入单价"/>
            </el-form-item>
          </el-col>
          <el-col :span="8" v-if="form.pricingMethod=='TIME'">
            <el-form-item label="工作时长" prop="workingHours">
              <el-input-number :min="1" :step="1" v-model="form.workingHours" placeholder="请输入工作时长"/>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="24">
            <el-form-item label="规格型号" prop="specification">
              <el-input
                v-model="form.specification"
                type="textarea"
                disabled
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row v-if="form.isCheck == 'N'">
          <el-col :span="8">
            <el-form-item label="报工数量" prop="quantityFeedback">
              <el-input disabled v-model="form.quantityFeedback" :disabled="form.status==='PREPARE'?false:true"/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="合格品数量" prop="quantityQualified">
              <el-input-number
                :min="0"
                @change="handleQuantityChanged"
                v-model="form.quantityQualified"
                placeholder="请输入合格品数量"
                :disabled="form.status==='PREPARE'?false:true"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="不良品数量" prop="quantityUnquanlified">
              <el-input-number
                :min="0"
                @change="handleQuantityChanged"
                v-model="form.quantityUnquanlified"
                placeholder="请输入不良品数量"
                :disabled="form.status==='PREPARE'?false:true"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row v-else>
          <el-col :span="8">
            <el-form-item label="报工数量" prop="quantityFeedback">
              <el-input disabled v-model="form.quantityFeedback"/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="待检测数量" prop="quantityUncheck">
              <el-input-number
                :min="0"
                @change="handleQuantityChanged"
                v-model="form.quantityUncheck"
                placeholder="请输入待检测数量"
                :disabled="form.status==='PREPARE'?false:true"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="报工人" prop="nickName">
              <el-input v-model="form.nickName" disabled placeholder="请选择报工人"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="报工时间" prop="feedbackTime">
              <el-date-picker
                clearable
                v-model="form.feedbackTime"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="请选择报工时间"
                :disabled="form.status==='PREPARE'?false:true"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8" v-if="form.isPra != 'N'">
            <el-form-item label="审核人" prop="recordNick">
              <el-input v-model="form.recordNick" placeholder="请选择审核人">
                <el-button
                  slot="append"
                  @click="handleUser2Select"
                  icon="el-icon-search"
                ></el-button>
              </el-input>
            </el-form-item>
            <UserSingleSelect
              ref="user2Select"
              @onSelected="onUser2Selected"
            ></UserSingleSelect>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="备注" prop="remark">
              <el-input
                v-model="form.remark"
                type="textarea"
                placeholder="请输入内容"
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>

      <el-tabs type="border-card" v-if="qcIpqc != null && qcIpqc.ipqcId != null">
        <el-tab-pane label="检验单信息">
          <el-descriptions :column="2" border>
            <el-descriptions-item
              label="检验单名称"
              label-style="margin-bottom: 20px; margin-top: 20px;"
              content-style="margin-bottom: 20px; margin-top: 20px;">{{ qcIpqc.ipqcName }}
            </el-descriptions-item>
            <el-descriptions-item
              label="检验单编号"
              label-style="margin-bottom: 20px; margin-top: 20px;"
              content-style="margin-bottom: 20px; margin-top: 20px;">{{ qcIpqc.ipqcCode }}
            </el-descriptions-item>
            <el-descriptions-item
              label="检验类型"
              label-style="margin-bottom: 20px; margin-top: 20px;"
              content-style="margin-bottom: 20px; margin-top: 20px;">{{ qcIpqc.ipqcType }}
            </el-descriptions-item>
            <el-descriptions-item
              label="检验日期"
              label-style="margin-bottom: 20px; margin-top: 20px;"
              content-style="margin-bottom: 20px; margin-top: 20px;">{{ qcIpqc.inspectDate }}
            </el-descriptions-item>
            <el-descriptions-item
              label="检验人"
              label-style="margin-bottom: 20px; margin-top: 20px;"
              content-style="margin-bottom: 20px; margin-top: 20px;">{{ qcIpqc.inspector }}
            </el-descriptions-item>
          </el-descriptions>
        </el-tab-pane>
        <el-tab-pane label="检验项目">
          <div class="info-container">
            <el-card shadow="always" v-if="qcIpqc.ipqcId != null" class="box-card">
              <IpqcSelect ref="line" :ipqcId="qcIpqc.ipqcId" :optType="optType"></IpqcSelect>
            </el-card>
          </div>
        </el-tab-pane>
        <el-tab-pane label="检验结果">
          <el-descriptions :column="2" border>
            <el-descriptions-item
              label="合格数量"
              label-style="margin-bottom: 20px; margin-top: 20px;"
              content-style="margin-bottom: 20px; margin-top: 20px;">{{ qcIpqc.quantityQualified }}
            </el-descriptions-item>
            <el-descriptions-item
              label="不合格数量"
              label-style="margin-bottom: 20px; margin-top: 20px;"
              content-style="margin-bottom: 20px; margin-top: 20px;">{{ qcIpqc.quantityUnqualified }}
            </el-descriptions-item>
            <el-descriptions-item
              label="合格率"
              label-style="margin-bottom: 20px; margin-top: 20px;"
              content-style="margin-bottom: 20px; margin-top: 20px;">
              {{ ((qcIpqc.quantityQualified / (qcIpqc.quantityCheck + qcIpqc.quantityUnqualified)) * 100).toFixed(2) }}%
            </el-descriptions-item>
            <el-descriptions-item
              label="检测结果"
              label-style="margin-bottom: 20px; margin-top: 20px;"
              content-style="margin-bottom: 20px; margin-top: 20px;">
              {{ qcIpqc.checkResult == 'ACCEPT' ? '检验通过' : '检验不通过' }}
            </el-descriptions-item>
            <el-descriptions-item
              label="备注"
              label-style="margin-bottom: 20px; margin-top: 20px;"
              content-style="margin-bottom: 20px; margin-top: 20px;">
              {{ qcIpqc.remark }}
            </el-descriptions-item>
          </el-descriptions>
        </el-tab-pane>
      </el-tabs>

      <div slot="footer" class="dialog-footer">
        <el-button
          type="primary"
          @click="cancel"
          v-if="optType == 'view' || form.status != 'PREPARE'"
        >返回
        </el-button>
        <el-button
          type="primary"
          @click="submitForm"
          v-if="form.status == 'PREPARE' && optType != 'view'"
        >保 存
        </el-button>
        <el-button
          type="primary"
          @click="handleSubmit"
          v-hasPermi="['mes:pro:feedback:tijiao']"
          v-if="form.status == 'PREPARE' && optType != 'view' && form.recordId != null">提交审批
        </el-button>
        <el-button
          type="success"
          @click="handleExecute"
          v-hasPermi="['mes:pro:feedback:shenhe']"
          v-if="form.status == 'APPROVING' && form.recordId != null && isSubmit"
        >审批通过
        </el-button>
        <el-button
          type="danger"
          @click="handleReject"
          v-hasPermi="['mes:pro:feedback:shenhe']"
          v-if="form.status == 'APPROVING' && form.recordId != null && isSubmit"
        >审批不通过
        </el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <feedback-info v-if="infoOpen" ref="feedbackInfo"></feedback-info>
  </div>
</template>

<script>
import { addFeedback, delFeedback, execute, getFeedback, getFeedbackInfo, listFeedback, updateFeedback, } from "@/api/mes/pro/feedback";
import WorkorderSelect from "@/components/workorderSelect/single.vue";
import WorkstationSelect from "@/components/workstationSelect/simpletableSingle.vue";
import UserSingleSelect from "@/components/userSelect/single.vue";
import ProtaskSelect from "@/components/TaskSelect/taskSelectSingle.vue";
import FeedbackInfo from "@/components/Feedback/feedbackInfo.vue";
import IpqcSelect from "@/components/ipqcSelect/single.vue";
import ProTask from "@/views/mes/pro/workticket/task/proTask.vue";

export default {
  name: "Feedback",
  components: {
    ProTask,
    IpqcSelect,
    WorkorderSelect,
    WorkstationSelect,
    UserSingleSelect,
    ProtaskSelect,
    FeedbackInfo,
  },
  dicts: ["mes_order_status", "mes_feedback_type", "pro_pricing_method"],
  data() {
    return {
      optType: undefined,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 生产报工记录表格数据
      feedbackList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,

      infoOpen: false,

      taskStatus: 'PROGRESS',

      isSubmit: true,

      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        feedbackType: null,
        workstationId: null,
        workstationCode: null,
        workstationName: null,
        workorderId: null,
        workorderCode: null,
        workorderName: null,
        taskId: null,
        taskCode: null,
        itemId: null,
        itemCode: null,
        itemName: null,
        unitOfMeasure: null,
        specification: null,
        quantity: null,
        quantityFeedback: null,
        quantityQualified: null,
        quantityUnquanlified: null,
        userName: null,
        nickName: null,
        feedbackChannel: null,
        feedbackTime: null,
        recordUser: null,
        recordNick: null,
        status: null,
      },
      // 表单参数
      form: {},

      qcIpqc: {},
      // 表单校验
      rules: {
        feedbackType: [
          {required: true, message: "报工类型不能为空", trigger: "change"},
        ],
        taskCode: [
          {required: true, message: "请选择生产任务", trigger: "blur"},
        ],
        workorderCode: [
          {required: true, message: "生产工单不能为空", trigger: "blur"},
        ],
        nickName: [
          {required: true, message: "请选择报工人", trigger: "blur"},
        ],
        feedbackTime: [
          {required: true, message: "请选择报工时间", trigger: "blur"},
        ],
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询生产报工记录列表 */
    getList() {
      this.loading = true;
      listFeedback(this.queryParams).then((response) => {
        this.feedbackList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        recordId: null,
        feedbackType: null,
        workstationId: null,
        workstationCode: null,
        workstationName: null,
        routeId: null,
        routeCode: null,
        processId: null,
        processCode: null,
        processName: null,
        workorderId: null,
        workorderCode: null,
        workorderName: null,
        taskId: null,
        taskCode: null,
        taskName: null,
        itemId: null,
        itemCode: null,
        itemName: null,
        specification: null,
        quantity: 0,
        quantityUncheck: 0,
        quantityFeedback: 0,
        quantityQualified: 0,
        quantityUnquanlified: 0,
        userName: null,
        nickName: null,
        feedbackChannel: null,
        feedbackTime: new Date(),
        recordUser: null,
        recordNick: null,
        status: "PREPARE",
        remark: null,
        attr1: null,
        attr2: null,
        attr3: null,
        attr4: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        workingHours: 1,
        isPra: null,
      };
      this.resetForm("form");
      this.qcIpqc = {};
    },
    handleQuantityChanged() {
      this.form.quantityFeedback =
        this.form.quantityQualified +
        this.form.quantityUnquanlified +
        this.form.quantityUncheck;
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.recordId);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加生产报工记录";
      this.optType = "add";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const recordId = row.recordId || this.ids;
      if (row.status == 'APPROVING') {
        getFeedbackInfo(recordId).then(response => {
          this.qcIpqc = response.data.qcIpqc || this.qcIpqc;
        });
      }

      getFeedback(recordId).then((response) => {
        this.form = response.data;
        this.open = true;
        this.isSubmit = true;
        this.title = "修改生产报工记录";
        this.optType = "edit";
      });
    },
    // 查询明细按钮操作
    handleView(row) {
      this.reset();
      const recordId = row.recordId || this.ids;
      getFeedback(recordId).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "查看生产报工单信息";
        this.optType = "view";
      });
    },
    // 查询明细按钮操作
    handleInfoView(row) {
      const recordId = row.recordId || this.ids;
      this.infoOpen = true;
      this.$nextTick(() => {
        this.$refs.feedbackInfo.init(recordId);
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.recordId != null) {
            updateFeedback(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addFeedback(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    handleSubmit() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.recordId != null) {
            this.isSubmit = false;
            this.form.status = "APPROVING";
            updateFeedback(this.form).then((response) => {
              this.$modal.msgSuccess("提交成功");
              this.open = false;
              this.getList();
            }).catch(() => {
              this.form.status = "PREPARE";
            });
          }
        }
      });
    },
    //审批通过执行
    handleExecute() {
      const data = this.form;
      this.$modal
        .confirm("是否确认报工审核完成？审核后不可更改！")
        .then(function () {
          return execute(data); //执行报工
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("执行成功");
          this.open = false;
        })
        .catch(() => {
        });
    },
    //审批不通过，拒绝
    handleReject() {
      this.form.status = "PREPARE";
      if (this.form.isCheck === 'Y') {
        this.form.quantityUncheck = this.form.quantityFeedback;
      }
      if (this.form.recordId != null) {
        updateFeedback(this.form).then((response) => {
          this.$modal.msgSuccess("提交成功");
          this.open = false;
          this.getList();
        });
      }
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const recordIds = row.recordId || this.ids;
      this.$modal
        .confirm('是否确认删除生产报工记录编号为"' + recordIds + '"的数据项？')
        .then(function () {
          return delFeedback(recordIds);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {
        });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "pro/feedback/export",
        {
          ...this.queryParams,
        },
        `feedback_${new Date().getTime()}.xlsx`
      );
    },
    //选择生产工单
    handleWorkorderSelect() {
      this.$refs.woSelect.showFlag = true;
    },
    onWorkorderSelected(row) {
      if (row != undefined && row != null) {
        this.form.workorderId = row.workorderId;
        this.form.workorderCode = row.workorderCode;
        this.form.workorderName = row.workorderName;
        this.form.itemId = row.productId;
        this.form.itemCode = row.productCode;
        this.form.itemName = row.productName;
        this.form.specification = row.productSpc;
        this.form.unitOfMeasure = row.unitOfMeasure;
      }
    },
    handleTaskSelect() {
      this.$refs.taskSelect.showFlag = true;
      this.$refs.taskSelect.getList();
    },
    onTaskSelected(row) {
      if (row != undefined && row != null) {
        this.form.taskId = row.taskId;
        this.form.taskCode = row.taskCode;
        this.form.taskName = row.taskName;
        this.form.workstationId = row.workstationId;
        this.form.workstationCode = row.workstationCode;
        this.form.workstationName = row.workstationName;
        this.form.processId = row.processId;
        this.form.processCode = row.processCode;
        this.form.processName = row.processName;
        this.form.routeId = row.routeId;
        this.form.routeCode = row.routeCode;
        this.form.isCheck = row.isCheck;
        this.form.nickName = row.attr1;
        this.form.userName = row.attr3;
        this.form.pricingMethod = row.pricingMethod;
        this.form.price = row.price;
        this.form.isPra = row.isPra;
        if (row.isCheck == "N") {
          this.form.quantityUncheck = 0;
        } else {
          this.form.quantityQualified = 0;
          this.form.quantityUnquanlified = 0;
        }
      }
    },
    //点击人员选择按钮
    handleUserSelect() {
      this.$refs.userSelect.showFlag = true;
    },
    //人员选择返回
    onUserSelected(row) {
      this.form.nickName = row.nickName;
      this.form.userName = row.userName;
    },
    //点击人员选择按钮
    handleUser2Select() {
      this.$refs.user2Select.showFlag = true;
    },
    //人员选择返回
    onUser2Selected(row) {
      this.form.recordUser = row.userName;
      this.form.recordNick = row.nickName;
    },
  },
};
</script>
<style scoped>
.production-info {
  border: 1px solid #ddd;
  padding: 16px;
  border-radius: 4px;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.details {
  flex-grow: 1;
  margin-left: 16px;
}

.status {
  margin-left: 16px;
}

.status-text {
  color: orange;
  border: 1px solid orange;
  padding: 4px 8px;
  border-radius: 4px;
}

.content {
  margin-top: 16px;
}
</style>
